﻿@inject IHttpService _httpService
@inject IPopupService PopupService
@inject NavigationManager NavigationManager

<MDCard>
    <DataTableCard TModel="OperationRecordOverviewModel" Headers="_headers" ApiUrl="@(_baseUrl)" Title="@($"{_name}列表")" ShowAddButton="false">
        <ItemColContent>
            @if (context.Header.Value == "actions")
            {
                <MIcon Color="success"
                       Class="mr-2"
                       OnClick="()=>LookItem(context.Item)">@IconType.Look.ToIconString()</MIcon>
            }
            else if (context.Header.Value == nameof(OperationRecordOverviewModel.Type))
            {
                <TypeChip Type="context.Item.Type" />
            }
            else if (context.Header.Value == nameof(OperationRecordOverviewModel.UserName))
            {
                <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.ReviewEditRecords.UserChip Id="@context.Item.UserId" Name="@context.Item.UserName" />
            }
            else if (context.Header.Value == nameof(OperationRecordOverviewModel.OperationTime))
            {
                @context.Item.OperationTime.ToString("yyyy-MM-dd HH:mm")
            }
            else
            {
                @context.Value
            }
        </ItemColContent>
    </DataTableCard>

</MDCard>


@code {
    private string _baseUrl = "api/account/ListOperationRecords";
    private string _name = "操作记录";

    private List<DataTableHeader<OperationRecordOverviewModel>> _headers = new List<DataTableHeader<OperationRecordOverviewModel>>
{
          new ()
          {
            Text= "Id",
            Align= DataTableHeaderAlign.Start,
            Value= nameof(OperationRecordOverviewModel.Id)
          },
          new (){ Text= "类型", Value= nameof(OperationRecordOverviewModel.Type)},
          new (){ Text= "目标Id", Value= nameof(OperationRecordOverviewModel.ObjectId)},
          new (){ Text= "用户", Value= nameof(OperationRecordOverviewModel.UserName)},
          new (){ Text= "IP", Value= nameof(OperationRecordOverviewModel.Ip)},
          new (){ Text= "Cookie", Value= nameof(OperationRecordOverviewModel.Cookie)},
          new (){ Text= "时间", Value= nameof(OperationRecordOverviewModel.OperationTime)},
          new (){ Text= "操作", Value= "actions",Sortable=false }
    };

    public void LookItem(OperationRecordOverviewModel model)
    {
        if (model.Type == OperationRecordType.Vote)
        {
            NavigationManager.NavigateTo("/votes/index/" + model.ObjectId);

        }
        else if (model.Type == OperationRecordType.Lottery)
        {
            NavigationManager.NavigateTo("/lotteries/index/" + model.ObjectId);

        }
        else if (model.Type == OperationRecordType.Score)
        {
            NavigationManager.NavigateTo("/entries/index/" + model.ObjectId);
        }
    }
}
